package br.com.vti.sisp_sicrim.antigo.controller.relatorios;

import java.io.FileNotFoundException;
import java.text.ParseException;
import java.util.Arrays;

import net.sf.jasperreports.engine.JRException;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.interceptor.download.InputStreamDownload;
import br.com.vti.sisp_sicrim.antigo.model.SicTabelas;
import br.com.vti.sisp_sicrim.antigo.model.Sisll001;
import br.com.vti.sisp_sicrim.antigo.util.Relatorios;
import br.com.vti.sisp_sicrim.antigo.util.Sessao;
import br.com.vti.sisp_sicrim.antigo.util.UtilBean;

/**
 * Classe responsavel por encapsular o tratamento e as consistencias da tela Idcs0000Report
 * 
 * @author Incode - Data: mai/2014
 * 
 */
public class Idcs0000Report {
	private String nomeClasse;
	private String matr;
	private String nome;
	private String org;
	private String cabecaGov;
	private int tatv;
	private String cabecaSeg;
	private int tdel;
	private String cabecaIde;
	private int tger;
	private String dataCorrente;
	private Integer dintabMatfun; // DB
	private Integer dintabDatatu; // DB
	public String codele;
	public String descri;
	public String desc;
	public String datapo;
	private String[] acs = new String[31];
	private String nroPagina;
	private Result result;
	private Sessao sessao;
	private Relatorios report;
	// Classes views
	SicTabelas vwDvetab = new SicTabelas();
	SicTabelas vwTabele = new SicTabelas();
	// Classes includes
	Sisll001 sisll001 = new Sisll001();

	public Idcs0000Report() throws JRException, ParseException {
		inicializar();
	}

	public Idcs0000Report(Sessao sessao) throws JRException, ParseException {
		this.sessao = sessao;
		inicializar();
	}

	public void inicializar() throws JRException, ParseException {
		report = new Relatorios();
		Arrays.fill(acs, "");
		cabecaGov = "SECRETARIA DE ESTADO DO PLANEJAMENTO E ORCAMENTO - SEPLAN";
		tatv = 0;
		cabecaSeg = "SECRETARIA DE ESTADO DA SEGURAN�A PUBLICA";
		tdel = 0;
		cabecaIde = "INSTITUTO DE IDENTIFICACAO CIVIL - IIC";
		tger = 0;
		dataCorrente = "0";
		nomeClasse = this.getClass().getSimpleName(); // *PROGRAM
		report.setNumeroRel(1, "C");
		{
			report.setNumeroLinhaRel(1, 1);
			{
				report.adicionaCampo(1, 1, "lit_1_1", "C", "", " ");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(2, 3);
			{
				report.adicionaCampo(1, 60, "Cabecagov", "X", "ZZZ.ZZ9", "");
				report.adicionaCampo(116, 7, "lit_116_7", "C", "", "PAGINA:");
				report.adicionaCampo(124, 5, "nroPagina", "S", "ZZZ.ZZ9", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(3, 2);
			{
				report.adicionaCampo(1, 60, "Cabecaseg", "X", "", "");
				report.adicionaCampo(116, 17, "lit_116_17", "C", "", "REL :    TABSENHA");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(4, 3);
			{
				report.adicionaCampo(1, 50, "Cabecaide", "X", "99/99/9999", "");
				report.adicionaCampo(116, 5, "lit_116_5", "C", "", "DATA:");
				report.adicionaCampo(122, 8, "dataCorrente", "N", "99/99/9999", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(6, 2);
			{
				report.adicionaCampo(1, 55, "lit_1_55", "C", "", "EMISSAO DO CADASTRO DE APOIO ==> TABELA DE FUNCIONARIOS");
				report.adicionaCampo(58, 32, "lit_58_32", "C", "", "HABILITADOS A UTILIZAR O SISTEMA");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(7, 1);
			{
				report.adicionaCampo(1, 1, "lit_1_1", "C", "", "-");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(8, 5);
			{
				report.adicionaCampo(1, 28, "lit_1_28", "C", "", "MATRIC.  NOME DO FUNCIONARIO");
				report.adicionaCampo(41, 15, "lit_41_15", "C", "", "VEI CNH MUL ARR");
				report.adicionaCampo(57, 52, "lit_57_52", "C", "", "IPV RF  PM. INF TAB SEN CRI IDC REN FUN SUP CMU  ORG");
				report.adicionaCampo(111, 3, "lit_111_3", "C", "", "RIA");
				report.adicionaCampo(116, 17, "lit_116_17", "C", "", "MAT.AT.  ATUALIZ.");
				report.setFimLinhaRel();
			}
		}
		report.setNumeroRel(2, "D");
		{
			report.setNumeroLinhaRel(1, 22);
			{
				report.adicionaCampo(1, 7, "Matr", "N", "", "");
				report.adicionaCampo(10, 30, "Nome", "X", "", "");
				report.adicionaCampo(42, 1, "Acs[2]", "X", "", "");
				report.adicionaCampo(46, 1, "Acs[3]", "X", "", "");
				report.adicionaCampo(50, 1, "Acs[4]", "X", "", "");
				report.adicionaCampo(54, 1, "Acs[5]", "X", "", "");
				report.adicionaCampo(58, 1, "Acs[6]", "X", "", "");
				report.adicionaCampo(62, 1, "Acs[7]", "X", "", "");
				report.adicionaCampo(66, 1, "Acs[8]", "X", "", "");
				report.adicionaCampo(70, 1, "Acs[9]", "X", "", "");
				report.adicionaCampo(74, 1, "Acs[10]", "X", "", "");
				report.adicionaCampo(78, 1, "Acs[11]", "X", "", "");
				report.adicionaCampo(82, 1, "Acs[12]", "X", "", "");
				report.adicionaCampo(86, 1, "Acs[13]", "X", "", "");
				report.adicionaCampo(90, 1, "Acs[14]", "X", "99", "");
				report.adicionaCampo(94, 1, "Acs[15]", "X", "99", "");
				report.adicionaCampo(98, 1, "Acs[16]", "X", "99", "");
				report.adicionaCampo(102, 1, "Acs[17]", "X", "99", "");
				report.adicionaCampo(107, 2, "Org", "N", "99", "");
				report.adicionaCampo(111, 1, "Acs[1]", "X", "", "");
				report.adicionaCampo(113, 7, "Dintabmatfun", "N", "", "");
				report.adicionaCampo(123, 8, "Dintabdatatu", "N", "99/99/9999", "");
				report.setFimLinhaRel();
			}
		}
		report.setNumeroRel(3, "D");
		{
			report.setNumeroLinhaRel(1, 1);
			{
				report.adicionaCampo(1, 1, "lit_1_1", "C", "", "-");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(2, 2);
			{
				report.adicionaCampo(1, 20, "lit_1_20", "C", "", "*** TOTAL ATIVO    =");
				report.adicionaCampo(22, 5, "Tatv", "N", "ZZ.ZZ9", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(3, 2);
			{
				report.adicionaCampo(1, 20, "lit_1_20", "C", "", "*** TOTAL EXCLUIDO =");
				report.adicionaCampo(22, 5, "Tdel", "N", "ZZ.ZZ9", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(4, 2);
			{
				report.adicionaCampo(1, 20, "lit_1_20", "C", "", "*** TOTAL GERAL    =");
				report.adicionaCampo(22, 5, "Tger", "N", "ZZ.ZZ9", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(5, 1);
			{
				report.adicionaCampo(1, 1, "lit_1_1", "C", "", "-");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(6, 1);
			{
				report.adicionaCampo(1, 50, "lit_1_50", "C", "", "                                                  ");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(7, 1);
			{
				report.adicionaCampo(1, 50, "lit_1_50", "C", "", "                    O R G A O S                   ");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(8, 1);
			{
				report.adicionaCampo(1, 50, "lit_1_50", "C", "", "                    - - - - - -                   ");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(9, 1);
			{
				report.adicionaCampo(1, 53, "lit_1_53", "C", "", "20 - DETRAN SAO LUIS      *  01 - CIRETRAN IMPERATRIZ");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(10, 1);
			{
				report.adicionaCampo(1, 53, "lit_1_53", "C", "", "02 - CIRETRAN CAXIAS      *  03 - CIRETRAN CODO      ");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(11, 1);
			{
				report.adicionaCampo(1, 53, "lit_1_53", "C", "", "04 - CIRETRAN BALSAS      *  05 - CIRETRAN BACABAL   ");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(12, 1);
			{
				report.adicionaCampo(1, 53, "lit_1_53", "C", "", "06 - CIRETRAN CHAPADINHA  *  07 - CIRETRAN PEDREIRAS ");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(13, 1);
			{
				report.adicionaCampo(1, 53, "lit_1_53", "C", "", "08 - CIRETRAN PINHEIRO    *  09 - CIRETRAN SANTA INES");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(14, 1);
			{
				report.adicionaCampo(1, 53, "lit_1_53", "C", "", "10 - CIRETRAN TIMON       *  11 - CIRETRAN ACAILANDIA");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(15, 1);
			{
				report.adicionaCampo(1, 54, "lit_1_54", "C", "", "12 - CIRETRAN PRES.DUTRA  *  13 - CIRETRAN B. DO CORDA");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(16, 1);
			{
				report.adicionaCampo(1, 53, "lit_1_53", "C", "", "14 - CIRETRAN GRAJAU                                 ");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(17, 1);
			{
				report.adicionaCampo(1, 54, "lit_1_54", "C", "", "30 - G E J U S P C        *  60 - SEFAZ               ");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(18, 1);
			{
				report.adicionaCampo(1, 54, "lit_1_54", "C", "", "70 - POLICIA MILITAR      *  99 - OUTROS              ");
				report.setFimLinhaRel();
			}
		}
		setCabecagov(cabecaGov);
		setCabecaseg(cabecaSeg);
		setCabecaide(cabecaIde);
	}

	public boolean validar() {
		// validar os campos recebidos da tela
		return true;
	}

	public String getMatr() {
		return matr;
	}

	public void setMatr(String matr) throws ParseException {
		this.matr = matr;
		report.adicionaValorReport("Matr", matr);
	}

	public String getNome() {
		return nome;
	}

	public void setNome(String nome) throws ParseException {
		this.nome = nome;
		report.adicionaValorReport("Nome", nome);
	}

	public String getOrg() {
		return org;
	}

	public void setOrg(String org) throws ParseException {
		this.org = org;
		report.adicionaValorReport("Org", org);
	}

	public String getCabecagov() {
		return cabecaGov;
	}

	public void setCabecagov(String cabecaGov) throws ParseException {
		this.cabecaGov = cabecaGov;
		report.adicionaValorReport("Cabecagov", cabecaGov);
	}

	public int getTatv() {
		return tatv;
	}

	public void setTatv(int tatv) throws ParseException {
		this.tatv = tatv;
		report.adicionaValorReport("Tatv", tatv);
	}

	public String getCabecaseg() {
		return cabecaSeg;
	}

	public void setCabecaseg(String cabecaSeg) throws ParseException {
		this.cabecaSeg = cabecaSeg;
		report.adicionaValorReport("Cabecaseg", cabecaSeg);
	}

	public int getTdel() {
		return tdel;
	}

	public void setTdel(int tdel) throws ParseException {
		this.tdel = tdel;
		report.adicionaValorReport("Tdel", tdel);
	}

	public String getCabecaide() {
		return cabecaIde;
	}

	public void setCabecaide(String cabecaIde) throws ParseException {
		this.cabecaIde = cabecaIde;
		report.adicionaValorReport("Cabecaide", cabecaIde);
	}

	public int getTger() {
		return tger;
	}

	public void setTger(int tger) throws ParseException {
		this.tger = tger;
		report.adicionaValorReport("Tger", tger);
	}

	public String getDataCorrente() {
		return dataCorrente;
	}

	public void setDataCorrente(String dataCorrente) throws ParseException {
		this.dataCorrente = dataCorrente;
		report.adicionaValorReport("dataCorrente", dataCorrente);
	}

	public String[] getAcs() {
		return acs;
	}

	public void setAcs(String[] acs) throws ParseException {
		this.acs = acs;
		report.adicionaValorReport("Acs[1]", acs[1]);
		report.adicionaValorReport("Acs[2]", acs[2]);
		report.adicionaValorReport("Acs[3]", acs[3]);
		report.adicionaValorReport("Acs[4]", acs[4]);
		report.adicionaValorReport("Acs[5]", acs[5]);
		report.adicionaValorReport("Acs[6]", acs[6]);
		report.adicionaValorReport("Acs[7]", acs[7]);
		report.adicionaValorReport("Acs[8]", acs[8]);
		report.adicionaValorReport("Acs[9]", acs[9]);
		report.adicionaValorReport("Acs[10]", acs[10]);
		report.adicionaValorReport("Acs[11]", acs[11]);
		report.adicionaValorReport("Acs[12]", acs[12]);
		report.adicionaValorReport("Acs[13]", acs[13]);
		report.adicionaValorReport("Acs[14]", acs[14]);
		report.adicionaValorReport("Acs[15]", acs[15]);
		report.adicionaValorReport("Acs[16]", acs[16]);
		report.adicionaValorReport("Acs[17]", acs[17]);
	}

	public String getAcs(int index) {
		return acs[index];
	}

	public void setAcs(int index, String acs) throws ParseException {
		this.acs[index] = acs;
		report.adicionaValorReport("Acs" + "[" + String.valueOf(index) + "]", acs);
	} // /

	public String getCodele() {
		return this.matr;
	}

	public void setCodele(String codele) throws ParseException {
		this.codele = codele;
		this.matr = UtilBean.subStr(codele, 0, 7);
		report.adicionaValorReport("Matr", UtilBean.subStr(codele, 0, 7));
	} // /

	public String getDescri() {
		return this.nome + this.desc;
	}

	public void setDescri(String descri) throws ParseException {
		this.descri = descri;
		this.nome = UtilBean.subStr(descri, 0, 30);
		report.adicionaValorReport("Nome", UtilBean.subStr(descri, 0, 30));
		this.desc = UtilBean.subStr(descri, 30, 30);
		report.adicionaValorReport("Desc", UtilBean.subStr(descri, 30, 30));
	} // /

	public String getDatapo() {
		return this.org;
	}

	public void setDatapo(String datapo) throws ParseException {
		this.datapo = datapo;
		this.org = UtilBean.subStr(datapo, 0, 2);
		report.adicionaValorReport("Org", UtilBean.subStr(datapo, 0, 2));
	}

	public String getNomeClasse() {
		return nomeClasse;
	}

	public void setNomeClasse(String nomeClasse) throws ParseException {
		this.nomeClasse = nomeClasse;
		report.adicionaValorReport("nomeClasse", nomeClasse);
	}

	public void setPageSize(int pagesize) throws JRException {
		report.setPageSize(pagesize);
	}

	public void setLineSize(int linesize) {
		report.setLineSize(linesize);
	}

	public int getPageSize() {
		return report.getPageSize();
	}

	public int getPageLine() {
		return report.getPageLine();
	}

	public void saltaLinhas(int qtdLinhas) throws ParseException, JRException {
		report.saltaLinhas(qtdLinhas);
	}

	public void gravaRelatorio(int nroRel) throws ParseException, JRException {
		setNroPagina(String.valueOf(report.getPageNumber()));
		report.gravaRelatorio(report, nroRel, false);
	}

	public InputStreamDownload imprimir() throws FileNotFoundException, JRException {
		return report.imprimir();
	}

	public Integer getDintabMatfun() {
		return dintabMatfun;
	}

	public void setDintabMatfun(Integer dintabMatfun) throws ParseException {
		this.dintabMatfun = dintabMatfun;
		report.adicionaValorReport("dintabMatfun", dintabMatfun);
	}

	public Integer getDintabDatatu() {
		return dintabDatatu;
	}

	public void setDintabDatatu(Integer dintabDatatu) throws ParseException {
		this.dintabDatatu = dintabDatatu;
		report.adicionaValorReport("dintabDatatu", dintabDatatu);
	}

	public String getNroPagina() {
		return nroPagina;
	}

	public void setNroPagina(String nroPagina) throws ParseException {
		this.nroPagina = nroPagina;
		report.adicionaValorReport("nroPagina", nroPagina);
	}

}
